from appium.webdriver.common.appiumby import AppiumBy

from 水质.utils.Logger import logger
from 水质.utils.click import clickText, clickId, swipeUp, swipeLeft, wait_Id, wait_clickId, swipeDown


def clickReload(driver):
    el = driver.find_element(AppiumBy.ID, "tv_reload")
    if el != None:
        el.click()
        logger.log("点击流速率定时间")
        rv_selection = wait_Id(driver, "rvSelection")
        child_elements = rv_selection.find_elements(AppiumBy.XPATH, ".//*")
        if len(child_elements) <= 0:
            logger.error("元素长度不够，率定时间列表为空")
        assert len(child_elements) > 0

        child_elements[0].click()
        logger.log("选择第一个时间")
        layout_root = wait_Id(driver, "layout_root")
        swipeUp(driver, layout_root)


def export_excel(driver):
    # 导出excel
    clickId(driver, "imageView19")
    wait_clickId(driver, "md_button_positive")
    wait_clickId(driver, "md_button_negative")


def checkTableThreeCheck(driver):
    wait_clickId(driver, "iv_menu")
    clickText(driver, "三线检定报表")
    clickReload(driver)
    export_excel(driver)
    smart_table = wait_Id(driver, "layout_root")
    swipeDown(driver, smart_table)
    swipeDown(driver, smart_table)

    wait_clickId(driver, "textView421")
    smart_table=wait_Id(driver,"smart_table")
    swipeLeft(driver,smart_table)
    swipeLeft(driver,smart_table)
    export_excel(driver)
    wait_clickId(driver, "iv_h")
    smart_table = wait_Id(driver, "smart_table")
    swipeLeft(driver, smart_table)
    export_excel(driver)
    wait_clickId(driver,"iv_menu")

